package dome3;

//泛型类
//<T>表示当前类是一个泛型类
class MyArry<T> {
    public Object[] array = new Object[3];
    public void setArray(int pos,T val) {
        array[pos] = val;
    }
    public T getArray(int pos) {
        return (T)array[pos];
    }
}
public class Text {
    public static void main(String[] args) {
        String a = "a";
        String b = "b";
        System.out.println(a.compareTo(b));
    }
    public static void main2(String[] args) {
        MyArry<Integer> myArry1 = new MyArry<Integer>();
        myArry1.setArray(0,10);
        myArry1.setArray(1,20);//在编译时，自动进行类型检查
        Integer val = myArry1.getArray(0);//在编译时，自动进行类型转换
        System.out.println(val);

        MyArry<String> myArry2 = new MyArry<String>();
        myArry2.setArray(0,"hello");
        myArry2.setArray(1,"java");
        String str = myArry2.getArray(0);
    }
    public static void main1(String[] args) {
        MyArry myArry = new MyArry();
        myArry.setArray(0,10);
//        myArry.setArray(1,"hello");

        String ret = (String)myArry.getArray(1);
    }
}
